import 'dart:math';

import 'package:card_swiper/card_swiper.dart';
import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:gourmet/color/hex.dart';
import 'package:gourmet/extensions/ex_widget.dart';
import 'package:gourmet/ui/draw_under_line.dart';
import 'package:gourmet/utils/colors.dart';
import 'package:gourmet/utils/radian.dart';
import 'package:gourmet/utils/styles.dart';
import 'package:gourmet/utils/svg.dart';
import 'package:gourmet/utils/tools.dart';

class InvitePrizesController extends GetxController {
  List<String> tags = [
    'zluc**邀请7个好朋友，获得7.5元红包',
    'gouc**邀请6个好朋友，获得6.5元红包',
    'taom**邀请5个好朋友，获得5.5元红包',
    'aitc**邀请4个好朋友，获得3.5元红包',
    'buck**邀请3个好朋友，获得1.5元红包'
  ];
}

class InvitePrizesPage extends GetView<InvitePrizesController> {
  const InvitePrizesPage({super.key});

  @override
  Widget build(BuildContext context) {
    return MediaQuery.removeViewPadding(
      context: context,
      removeTop: true,
      removeLeft: true,
      removeRight: true,
      removeBottom: true,
      child: Scaffold(
        backgroundColor: HexColor(ColorsUtils.colorF7f7),
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(80 + Get.mediaQuery.padding.top),
          child: AnnotatedRegion<SystemUiOverlayStyle>(
            value: SystemUiOverlayStyle.light,
            child: Container(
              padding: Get.mediaQuery.padding,
              height: 80 + Get.mediaQuery.padding.top,
              //linear-gradient(180deg, rgba(255, 153, 0, 1) 0%, rgba(255, 153, 0, 1) 0%, rgba(255, 100, 77, 1) 100%, rgba(255, 100, 77, 1) 100%)
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: [
                    ColorsUtils.rgba(255, 153, 0, 1),
                    ColorsUtils.rgba(255, 153, 0, 1),
                    ColorsUtils.rgba(255, 100, 77, 1),
                    ColorsUtils.rgba(255, 100, 77, 1),
                  ],
                  stops: const [
                    0,
                    0,
                    1,
                    1,
                  ],
                  end: Alignment.topCenter,
                  begin: Alignment.bottomCenter,
                  transform: GradientRotation(
                    RadianUtils.angleToRadian(180),
                  ),
                ),
              ),
              child: Column(
                children: [
                  Stack(
                    children: [
                      Container(
                        height: 40,
                        alignment: Alignment.center,
                        child: Text(
                          '邀请有奖',
                          style: StylesUtils.customTextStyle(
                            fontSize: StylesUtils.fontSize16,
                            fontWeight: FontWeight.w700,
                          ),
                        ),
                      ),
                      Positioned(
                        width: 40,
                        height: 40,
                        top: 0,
                        left: 0,
                        child: const Center(
                          child: Icon(
                            CupertinoIcons.chevron_back,
                            color: Colors.white,
                            size: 20,
                          ),
                        ).onTap(Get.back),
                      ),
                      Positioned(
                        width: 80,
                        height: 40,
                        top: 0,
                        right: 0,
                        child: Center(
                          child: Text(
                            '活动说明',
                            style: StylesUtils.customTextStyle(
                              fontSize: StylesUtils.fontSize15,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                  Expanded(
                    child: Swiper.list<String>(
                      list: controller.tags,
                      builder: (ctx, value, index) {
                        return Center(
                          child: Text.rich(
                            TextSpan(
                              children: [
                                WidgetSpan(
                                  child: Icon(
                                    CupertinoIcons.speaker_3_fill,
                                    size: 15,
                                    color: HexColor('#fed23d'),
                                  ),
                                ),
                                TextSpan(
                                  text: ' $value',
                                  style: StylesUtils.customTextStyle(
                                    fontSize: StylesUtils.fontSize13,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        );
                      },
                      autoplay: true,
                      autoplayDelay: 5000,
                      duration: 2000,
                      scrollDirection: Axis.vertical,
                      itemHeight: 40,
                      itemWidth: Get.width,
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
        body: SingleChildScrollView(
          padding: const EdgeInsets.only(bottom: 30),
          child: Column(
            children: [
              Container(
                width: 345,
                height: 180,
                margin: EdgeInsets.only(
                  top: 50,
                  left: (Get.width - 345) / 2,
                  right: (Get.width - 345) / 2,
                ),
                child: Stack(
                  clipBehavior: Clip.none,
                  children: [
                    Container(
                      height: 67,
                      decoration: BoxDecoration(
                        image: DecorationImage(
                          image: ToolsUtils.assetImage('u353.png'),
                        ),
                      ),
                    ),
                    Positioned(
                      height: 130,
                      top: -30,
                      left: 0,
                      right: 0,
                      child: Center(
                        child: SizedBox(
                          width: 290,
                          height: 130,
                          child: CustomPaint(
                            painter: _CircularPainter(),
                            child: Row(
                              children: [
                                SizedBox(
                                  width: 200,
                                  height: 130,
                                  child: Column(
                                    children: [
                                      Padding(
                                        padding: const EdgeInsets.only(top: 15),
                                        child: Row(
                                          children: [
                                            Container(
                                              margin: const EdgeInsets.only(
                                                  left: 50, right: 10),
                                              alignment: Alignment.centerLeft,
                                              child: Text(
                                                '无门槛',
                                                style:
                                                    StylesUtils.customTextStyle(
                                                  color: ColorsUtils.colorFf00,
                                                  fontSize:
                                                      StylesUtils.fontSize24,
                                                ),
                                              ),
                                            ),
                                            Expanded(
                                              child: Column(
                                                children: [
                                                  Align(
                                                    alignment:
                                                        Alignment.centerLeft,
                                                    child: Container(
                                                      constraints:
                                                          const BoxConstraints
                                                              .expand(
                                                              width: 30,
                                                              height: 15),
                                                      alignment:
                                                          Alignment.center,
                                                      decoration: BoxDecoration(
                                                        borderRadius:
                                                            BorderRadius
                                                                .circular(8),
                                                        color: ColorsUtils.rgba(
                                                            204, 153, 0, 1),
                                                      ),
                                                      child: Text(
                                                        '平台',
                                                        style: StylesUtils
                                                            .customTextStyle(
                                                                fontSize:
                                                                    StylesUtils
                                                                        .fontSize9),
                                                      ),
                                                    ),
                                                  ),
                                                  Container(
                                                    margin:
                                                        const EdgeInsets.only(
                                                            top: 5),
                                                    alignment:
                                                        Alignment.centerLeft,
                                                    child: Text(
                                                      '红包',
                                                      style: StylesUtils
                                                          .customTextStyle(
                                                        fontSize: StylesUtils
                                                            .fontSize12,
                                                        color: ColorsUtils
                                                            .colorFf00,
                                                      ),
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ),
                                          ],
                                        ),
                                      ),
                                      Container(
                                        alignment: Alignment.center,
                                        margin: const EdgeInsets.only(
                                            top: 5, bottom: 10),
                                        child: DottedBorder(
                                          strokeWidth: 1,
                                          padding: EdgeInsets.zero,
                                          color:
                                              HexColor(ColorsUtils.colorFf64),
                                          child: const SizedBox(
                                            width: 135,
                                            height: 1,
                                          ),
                                        ),
                                      ),
                                      Center(
                                        child: Text(
                                          '每邀请1个好友创建可得',
                                          style: StylesUtils.customTextStyle(
                                            color: ColorsUtils.colorFf66,
                                            fontSize: StylesUtils.fontSize12,
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                                SizedBox(
                                  width: 90,
                                  height: 130,
                                  child: CustomPaint(
                                    painter: _RightDrawPainter(),
                                    child: Container(
                                      margin: const EdgeInsets.only(top: 25),
                                      alignment: Alignment.topCenter,
                                      child: Text.rich(
                                        TextSpan(
                                          children: [
                                            TextSpan(
                                              text: '5',
                                              style:
                                                  StylesUtils.customTextStyle(
                                                fontSize:
                                                    StylesUtils.fontSize48,
                                                color: ColorsUtils.colorFf00,
                                              ),
                                            ),
                                            TextSpan(
                                              text: '毛',
                                              style:
                                                  StylesUtils.customTextStyle(
                                                fontSize:
                                                    StylesUtils.fontSize13,
                                                color: ColorsUtils.colorFf00,
                                              ),
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),

                        // child: Material(
                        //   shape:
                        //       _CouponShapeBorder(lineRate: 0.6896551724137931),
                        //   child: SizedBox(
                        //     width: 290,
                        //     height: 130,
                        //     child: Row(
                        //       children: [
                        //         Container(
                        //           width: 200,
                        //           color: HexColor('##fff5d2'),
                        //         ),
                        //         Expanded(
                        //           child: Container(
                        //             color: HexColor('#fed23d'),
                        //           ),
                        //         ),
                        //       ],
                        //     ),
                        //   ),
                        // ),
                      ),
                    ),
                    Positioned(
                      height: 139,
                      bottom: 0,
                      left: 0,
                      right: 0,
                      child: Container(
                        height: 139,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          image: DecorationImage(
                            image: ToolsUtils.assetImage('u356.png'),
                          ),
                        ),
                        child: Container(
                          constraints: const BoxConstraints.expand(
                              width: 215, height: 45),
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(23),
                            gradient: LinearGradient(
                              //linear-gradient(90deg, rgba(255, 191, 30, 1) 0%, rgba(255, 191, 30, 1) 0%, rgba(255, 255, 0, 1) 100%, rgba(255, 255, 0, 1) 100%)
                              colors: [
                                ColorsUtils.rgba(255, 191, 30, 1),
                                ColorsUtils.rgba(255, 191, 30, 1),
                                ColorsUtils.rgba(255, 255, 0, 1),
                                ColorsUtils.rgba(255, 255, 0, 1),
                              ],
                              stops: const [0, 0, 1, 1],
                              begin: Alignment.centerLeft,
                              end: Alignment.centerRight,
                              transform: GradientRotation(
                                RadianUtils.angleToRadian(90),
                              ),
                            ),
                          ),
                          child: Text(
                            '立即邀请好友',
                            style: StylesUtils.customTextStyle(
                              fontSize: StylesUtils.fontSize16,
                              color: ColorsUtils.colorCc33,
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                margin: insets,
                padding: const EdgeInsets.all(15),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(10),
                ),
                child: ListBody(
                  children: [
                    Container(
                      alignment: Alignment.centerLeft,
                      padding: const EdgeInsets.only(bottom: 15),
                      child: Text(
                        '我的收益',
                        style: StylesUtils.customTextStyle(
                          fontSize: StylesUtils.fontSize15,
                          fontWeight: FontWeight.w700,
                          color: ColorsUtils.color0000,
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 56,
                      child: CustomPaint(
                        painter: _DrawLinePainter(),
                        child: Row(
                          children: [
                            Expanded(
                              child: Column(
                                children: [
                                  Center(
                                    child: Text.rich(
                                      TextSpan(
                                        children: [
                                          TextSpan(
                                            text: '100',
                                            style: StylesUtils.customTextStyle(
                                              fontSize: StylesUtils.fontSize28,
                                              fontWeight: FontWeight.w700,
                                              color: ColorsUtils.colorFf64,
                                            ),
                                          ),
                                          TextSpan(
                                            text: '元',
                                            style: StylesUtils.customTextStyle(
                                              color: ColorsUtils.color7979,
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                  Container(
                                    margin: const EdgeInsets.only(top: 10),
                                    alignment: Alignment.center,
                                    child: Text(
                                      '累计邀请收益',
                                      style: StylesUtils.customTextStyle(
                                        fontSize: StylesUtils.fontSize12,
                                        color: ColorsUtils.color9999,
                                      ),
                                    ),
                                  )
                                ],
                              ),
                            ),
                            Expanded(
                              child: Column(
                                children: [
                                  Center(
                                    child: Text.rich(
                                      TextSpan(
                                        children: [
                                          TextSpan(
                                            text: '20',
                                            style: StylesUtils.customTextStyle(
                                              fontSize: StylesUtils.fontSize28,
                                              fontWeight: FontWeight.w700,
                                              color: ColorsUtils.colorFf64,
                                            ),
                                          ),
                                          TextSpan(
                                            text: '人',
                                            style: StylesUtils.customTextStyle(
                                              color: ColorsUtils.color7979,
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                  Container(
                                    margin: const EdgeInsets.only(top: 10),
                                    alignment: Alignment.center,
                                    child: Text(
                                      '成功邀请人数',
                                      style: StylesUtils.customTextStyle(
                                        fontSize: StylesUtils.fontSize12,
                                        color: ColorsUtils.color9999,
                                      ),
                                    ),
                                  )
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                margin: insets,
                padding: const EdgeInsets.all(15),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(10),
                ),
                child: ListBody(
                  children: [
                    Container(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '邀请记录',
                        style: StylesUtils.customTextStyle(
                          fontSize: StylesUtils.fontSize15,
                          fontWeight: FontWeight.w700,
                          color: ColorsUtils.color0000,
                        ),
                      ),
                    ),
                    DrawUnderLine(
                      dx: 0,
                      dy: 0,
                      strokeWidth: 2,
                      color: HexColor(ColorsUtils.colorF5f5),
                      child: Container(
                        padding: const EdgeInsets.only(top: 15, bottom: 15),
                        child: Column(
                          children: [
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  '被邀请人手机号：136****5678',
                                  style: StylesUtils.customTextStyle(
                                    color: ColorsUtils.color0000,
                                  ),
                                ),
                                Text(
                                  '0.5元红包',
                                  style: StylesUtils.customTextStyle(
                                    color: ColorsUtils.color7979,
                                  ),
                                ),
                              ],
                            ),
                            Padding(
                              padding: const EdgeInsets.only(top: 15),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(
                                    '2097-11-16 注册',
                                    style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.colorCccc,
                                      fontSize: StylesUtils.fontSize12,
                                    ),
                                  ),
                                  Text(
                                    '未下单',
                                    style: StylesUtils.customTextStyle(
                                      fontSize: StylesUtils.fontSize12,
                                      color: ColorsUtils.colorCccc,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    DrawUnderLine(
                      dx: 0,
                      dy: 0,
                      strokeWidth: 2,
                      color: HexColor(ColorsUtils.colorF5f5),
                      child: Container(
                        padding: const EdgeInsets.only(top: 15, bottom: 15),
                        child: Column(
                          children: [
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  '被邀请人手机号：136****5678',
                                  style: StylesUtils.customTextStyle(
                                    color: ColorsUtils.color0000,
                                  ),
                                ),
                                Text(
                                  '0.5元红包',
                                  style: StylesUtils.customTextStyle(
                                    color: ColorsUtils.color7979,
                                  ),
                                ),
                              ],
                            ),
                            Padding(
                              padding: const EdgeInsets.only(
                                top: 15,
                              ),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(
                                    '2097-11-16 注册',
                                    style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.colorCccc,
                                      fontSize: StylesUtils.fontSize12,
                                    ),
                                  ),
                                  Text(
                                    '发放中',
                                    style: StylesUtils.customTextStyle(
                                      fontSize: StylesUtils.fontSize12,
                                      color: ColorsUtils.colorCccc,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    DrawUnderLine(
                      dx: 0,
                      dy: 0,
                      strokeWidth: 2,
                      color: HexColor(ColorsUtils.colorF5f5),
                      child: Container(
                        padding: const EdgeInsets.only(top: 15, bottom: 15),
                        child: Column(
                          children: [
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  '被邀请人手机号：136****5678',
                                  style: StylesUtils.customTextStyle(
                                    color: ColorsUtils.color0000,
                                  ),
                                ),
                                Text(
                                  '0.5元红包',
                                  style: StylesUtils.customTextStyle(
                                    color: ColorsUtils.color7979,
                                  ),
                                ),
                              ],
                            ),
                            Padding(
                              padding: const EdgeInsets.only(top: 15),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(
                                    '2097-11-16 注册',
                                    style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.colorCccc,
                                      fontSize: StylesUtils.fontSize12,
                                    ),
                                  ),
                                  Text(
                                    '已发放',
                                    style: StylesUtils.customTextStyle(
                                      fontSize: StylesUtils.fontSize12,
                                      color: ColorsUtils.colorCccc,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    for (var i = 0; i < 10; i++)
                      DrawUnderLine(
                        dx: 0,
                        dy: 0,
                        strokeWidth: 2,
                        color: HexColor(ColorsUtils.colorF5f5),
                        child: Container(
                          padding: const EdgeInsets.only(top: 15, bottom: 15),
                          child: Column(
                            children: [
                              Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(
                                    '被邀请人手机号：136****5678',
                                    style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color0000,
                                    ),
                                  ),
                                  Text(
                                    '0.5元红包',
                                    style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color7979,
                                    ),
                                  ),
                                ],
                              ),
                              Padding(
                                padding: const EdgeInsets.only(top: 15),
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text(
                                      '2097-11-16 注册',
                                      style: StylesUtils.customTextStyle(
                                        color: ColorsUtils.colorCccc,
                                        fontSize: StylesUtils.fontSize12,
                                      ),
                                    ),
                                    Text(
                                      '已发放',
                                      style: StylesUtils.customTextStyle(
                                        fontSize: StylesUtils.fontSize12,
                                        color: ColorsUtils.colorCccc,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                  ],
                ),
              )
            ],
          ),
        ),
        bottomNavigationBar: SafeArea(
          bottom: true,
          child: Container(
            height: 90,
            color: Colors.white,
            padding: const EdgeInsets.symmetric(vertical: 10),
            child: Row(
              children: [
                Expanded(
                  child: Column(
                    children: [
                      Center(
                        child:
                            SvgUtils.assetName('u9346', width: 50, height: 50),
                      ),
                      Expanded(
                        child: Center(
                          child: Text(
                            '微信好友',
                            style: StylesUtils.customTextStyle(
                              fontSize: StylesUtils.fontSize12,
                              color: ColorsUtils.color0000,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Expanded(
                  child: Column(
                    children: [
                      Center(
                        child:
                            SvgUtils.assetName('u9347', width: 50, height: 50),
                      ),
                      Expanded(
                        child: Center(
                          child: Text(
                            '微信朋友圈',
                            style: StylesUtils.customTextStyle(
                              fontSize: StylesUtils.fontSize12,
                              color: ColorsUtils.color0000,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Expanded(
                  child: Column(
                    children: [
                      Center(
                        child:
                            SvgUtils.assetName('u9348', width: 50, height: 50),
                      ),
                      Expanded(
                        child: Center(
                          child: Text(
                            'QQ好友',
                            style: StylesUtils.customTextStyle(
                              fontSize: StylesUtils.fontSize12,
                              color: ColorsUtils.color0000,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Expanded(
                  child: Column(
                    children: [
                      Center(
                        child:
                            SvgUtils.assetName('u9349', width: 50, height: 50),
                      ),
                      Expanded(
                        child: Center(
                          child: Text(
                            'QQ空间',
                            style: StylesUtils.customTextStyle(
                              fontSize: StylesUtils.fontSize12,
                              color: ColorsUtils.color0000,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  EdgeInsets get insets {
    return EdgeInsets.only(
        left: (Get.width - 345) / 2, right: (Get.width - 345) / 2, top: 10);
  }
}

// class _DrawCustomPainter extends CustomPainter {
//   @override
//   void paint(Canvas canvas, Size size) {
//     Rect rect = Offset.zero & size;
//     RRect rRect = RRect.fromLTRBAndCorners(
//       rect.left,
//       rect.top,
//       rect.right,
//       rect.bottom,
//       topLeft: const Radius.circular(5),
//       topRight: const Radius.circular(5),
//     );
//     final paint = Paint()
//       ..style = PaintingStyle.fill
//       ..strokeCap = StrokeCap.square
//       ..color = HexColor('#ec4619');
//     // canvas.drawRRect(rRect, paint);

//     ///创建路径
//     var path = Path();
//     path.addRRect(rRect);
//     path.moveTo(0, 0);

//     ///A点 设置初始绘制点
//     path.lineTo(0, size.height - 20);

//     /// 绘制到 B点（100，0）
//     path.cubicTo(
//         0, size.height - 20, size.width / 2, 0, size.width, size.height - 20);

//     /// 绘制到 C点（214, 55）
//     // path.cubicTo(size.width - 100, 0, 214, 25, size.width, size.height);

//     path.fillType = PathFillType.evenOdd;

//     ///绘制 Path
//     canvas.drawPath(path, paint);
//   }

//   @override
//   bool shouldRepaint(covariant CustomPainter oldDelegate) {
//     return true;
//   }
// }

// class _DrawBottomPainter extends CustomPainter {
//   @override
//   void paint(Canvas canvas, Size size) {
//     Rect rect = Offset.zero & size;
//     RRect rRect = RRect.fromLTRBAndCorners(
//         rect.left, rect.top, rect.right, rect.bottom,
//         bottomLeft: const Radius.circular(5),
//         bottomRight: const Radius.circular(5));
//     final paint = Paint()
//       ..shader = LinearGradient(
//         colors: [HexColor('#f97138'), HexColor('#f65623')],
//         begin: Alignment.topCenter,
//         end: Alignment.bottomCenter,
//         stops: const [0, 1],
//       ).createShader(rect)
//       ..style = PaintingStyle.fill
//       ..strokeCap = StrokeCap.square;
//     canvas.drawRRect(rRect, paint);

//     // Path path = Path();
//     // path.addRRect(rRect);
//     // path.moveTo(0, 0);
//     // path.cubicTo(0, 10, 48, 0, size.width / 2, 0);
//     // path.cubicTo(size.width - 48, 0, size.width - 10, 10, size.width, 0);
//     // path.lineTo(size.width, size.height);
//     // path.lineTo(0, size.height);
//     // path.close();
//     // canvas.drawPath(path, paint);
//   }

//   @override
//   bool shouldRepaint(covariant CustomPainter oldDelegate) {
//     return true;
//   }
// }

// class _DrawBottomCustomClipper extends CustomClipper<Path> {
//   @override
//   Path getClip(Size size) {
//     Path path = Path();
//     Rect rect = Offset.zero & size;
//     RRect rRect = RRect.fromLTRBAndCorners(
//       rect.left,
//       rect.top,
//       rect.right,
//       rect.bottom,
//       bottomLeft: const Radius.circular(5),
//       bottomRight: const Radius.circular(5),
//     );
//     path.addRRect(rRect);

//     path.moveTo(0, 0);
//     path.cubicTo(0, 10, 48, 0, size.width / 2, 20);
//     path.cubicTo(size.width - 48, 20, size.width - 10, 10, size.width, 0);
//     path.lineTo(size.width, 0);
//     path.lineTo(size.width, size.height);
//     path.lineTo(0, size.height);
//     path.close();
//     path.fillType = PathFillType.evenOdd;
//     return path;
//   }

//   @override
//   bool shouldReclip(covariant CustomClipper oldClipper) {
//     return true;
//   }
// }

// class _CouponShapeBorder extends ShapeBorder {
//   final int holeCount; //我们打洞的个数
//   final double lineRate; //确定白线在控件中的位置 按照0 - 1 来算
//   final bool dash; //判断是否是虚线
//   final Color color; //线的颜色

//   _CouponShapeBorder(
//       {this.holeCount = 6,
//       this.lineRate = 0.718,
//       this.dash = true,
//       this.color = Colors.white});

//   @override
//   Path getOuterPath(Rect rect, {TextDirection? textDirection}) {
//     var path = Path();
//     var w = rect.width;
//     var h = rect.height;
//     var d = h / (1 + 2 * holeCount);

//     ///这个路径就是直接吧我们的rect放上去就是我们的控件本身的path  不需要进行任何裁剪和其他操作
//     path.addRect(rect);

//     _formHoldLeft(path, d);
//     //#fff5d2

//     _formHoldRight(path, w, d);
//     _formHoleTop(path, rect);
//     _formHoleBottom(path, rect);

//     ///这个是官方文档需要我们填的  但是也需要我们的path是从getInnerPath中返回的(这个重写函数感觉写不写没多大影响！！！有兴趣的可以试试)
//     path.fillType = PathFillType.evenOdd;
//     return path;
//   }

//   void _formHoldLeft(Path path, double d) {
//     for (int i = 0; i < holeCount; i++) {
//       var left = -d / 2;
//       var top = 0.0 + d + 2 * d * (i);
//       var right = left + d;
//       var bottom = top + d;
//       path.addArc(Rect.fromLTRB(left, top, right, bottom), -pi / 2, pi);
//     }
//   }

//   void _formHoldRight(Path path, double w, double d) {
//     for (int i = 0; i < holeCount; i++) {
//       var left = -d / 2 + w;
//       var top = 0.0 + d + 2 * d * (i);
//       var right = left + d;
//       var bottom = top + d;
//       path.addArc(Rect.fromLTRB(left, top, right, bottom), pi / 2, pi);
//     }
//   }

//   void _formHoleBottom(Path path, Rect rect) {
//     path.addArc(
//         Rect.fromCenter(
//             center: Offset(lineRate * rect.width, rect.height),
//             width: 13.0,
//             height: 13.0),
//         pi,
//         pi);
//   }

//   void _formHoleTop(Path path, Rect rect) {
//     path.addArc(
//         Rect.fromCenter(
//             center: Offset(lineRate * rect.width, 0),
//             width: 13.0,
//             height: 13.0),
//         0,
//         pi);
//   }

//   @override
//   void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {
//     var paint = Paint()
//       ..color = color
//       ..strokeWidth = 1.5
//       ..style = PaintingStyle.stroke
//       ..strokeJoin = StrokeJoin.round;
//     var d = rect.height / (1 + 2 * holeCount);
//     if (dash) {
//       //虚线
//       _drawDashLine(canvas, Offset(lineRate * rect.width, d / 2),
//           rect.height / 16, rect.height - 13, paint);
//     } else {
//       //实线
//       canvas.drawLine(Offset(lineRate * rect.width, d / 2),
//           Offset(lineRate * rect.width, rect.height - d / 2), paint);
//     }
//   }

//   void _drawDashLine(
//       Canvas canvas, Offset start, double count, double length, Paint paint) {
//     var step = length / count / 2;
//     for (int i = 0; i < count; i++) {
//       var offset = start + Offset(0, 2 * step * i);
//       canvas.drawLine(offset, offset + Offset(0, step), paint);
//     }
//   }

//   @override
//   EdgeInsetsGeometry get dimensions => throw UnimplementedError();

//   @override
//   Path getInnerPath(Rect rect, {TextDirection? textDirection}) {
//     throw UnimplementedError();
//   }

//   @override
//   ShapeBorder scale(double t) {
//     throw UnimplementedError();
//   }
// }

// class _LeftDrawPainter extends CustomPainter {
//   @override
//   void paint(Canvas canvas, Size size) {
//     Rect rect = Offset.zero & size;
//     var path = Path();
//     path.addRect(rect);
//     var h = rect.height;
//     var holeCount = 6;
//     var d = h / (1 + 2 * holeCount);
//     _formHoldLeft(path, d, holeCount);
//     path.fillType = PathFillType.evenOdd;
//     var paint = Paint()
//       ..color = HexColor('#fff5d2')
//       ..style = PaintingStyle.fill
//       ..strokeJoin = StrokeJoin.round;
//     canvas.drawPath(path, paint);
//   }

//   void _formHoldLeft(Path path, double d, int holeCount) {
//     for (int i = 0; i < holeCount; i++) {
//       var left = -d / 2;
//       var top = 0.0 + d + 2 * d * (i);
//       var right = left + d;
//       var bottom = top + d;
//       path.addArc(Rect.fromLTRB(left, top, right, bottom), -pi / 2, pi);
//     }
//   }

//   @override
//   bool shouldRepaint(covariant CustomPainter oldDelegate) {
//     return true;
//   }
// }

class _RightDrawPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    Rect rect = Offset.zero & size;
    var path = Path();
    path.addRect(rect);
    var h = rect.height;
    var holeCount = 6;
    var d = h / (1 + 2 * holeCount);
    _formHoldRight(path, rect.width, d, holeCount);
    path.fillType = PathFillType.evenOdd;
    var paint = Paint()
      ..color = HexColor('#fed23d')
      ..style = PaintingStyle.fill
      ..strokeJoin = StrokeJoin.round;
    canvas.drawPath(path, paint);
  }

  void _formHoldRight(Path path, double w, double d, int holeCount) {
    for (int i = 0; i < holeCount; i++) {
      var left = -d / 2 + w;
      var top = 0.0 + d + 2 * d * (i);
      var right = left + d;
      var bottom = top + d;
      path.addArc(Rect.fromLTRB(left, top, right, bottom), pi / 2, pi);
    }
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
}

class _CircularPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    // _formHoldRightDraw(canvas, const Size(90, 130));
    _formHoldLeftDraw(canvas, const Size(200, 130));
    _formHoleTop(size);
  }

  void _formHoleTop(Size size) {
    Rect rect = Offset.zero & size;
    var path = Path();
    path.addRect(rect);
    path.addArc(
        Rect.fromCenter(
            center: const Offset(200, 0), width: 13.0, height: 13.0),
        0,
        pi);
    path.fillType = PathFillType.evenOdd;
  }

  void _formHoldLeftDraw(Canvas canvas, Size size) {
    Rect rect = Rect.fromLTWH(0, 0, size.width, size.height);
    var path = Path();
    path.addRect(rect);
    var h = rect.height;
    var holeCount = 6;
    var d = h / (1 + 2 * holeCount);
    _formHoldLeft(path, d, holeCount);
    path.fillType = PathFillType.evenOdd;
    var paint = Paint()
      ..color = HexColor('#fff5d2')
      ..style = PaintingStyle.fill
      ..strokeJoin = StrokeJoin.round;
    canvas.drawPath(path, paint);
  }

  void _formHoldLeft(Path path, double d, int holeCount) {
    for (int i = 0; i < holeCount; i++) {
      var left = -d / 2;
      var top = d + 2 * d * i;
      var right = left + d;
      var bottom = top + d;
      path.addArc(Rect.fromLTRB(left, top, right, bottom), -pi / 2, pi);
    }
  }

  // void _formHoldRightDraw(Canvas canvas, Size size) {
  //   Rect rect = Rect.fromLTWH(0, 0, size.width, size.height);
  //   var path = Path();
  //   path.addRect(rect);
  //   var h = rect.height;
  //   var holeCount = 6;
  //   var d = h / (1 + 2 * holeCount);
  //   _formHoldRight(path, rect.width, d, holeCount);
  //   path.fillType = PathFillType.evenOdd;
  //   var paint = Paint()
  //     ..color = HexColor('#fed23d')
  //     ..style = PaintingStyle.fill
  //     ..strokeJoin = StrokeJoin.round;
  //   canvas.drawPath(path, paint);
  // }

  // void _formHoldRight(Path path, double w, double d, int holeCount) {
  //   for (int i = 0; i < holeCount; i++) {
  //     var left = -d / 2 + w;
  //     var top = d + 2 * d * i;
  //     var right = left + d;
  //     var bottom = top + d;
  //     path.addArc(Rect.fromLTRB(left, top, right, bottom), pi / 2, pi);
  //   }
  // }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
}

class _DrawLinePainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint()
      ..strokeWidth = 1
      ..style = PaintingStyle.stroke
      ..color = HexColor(ColorsUtils.colorF5f5);
    canvas.drawLine(
        Offset(size.width / 2, 0), Offset(size.width / 2, 56), paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
}
